<?php
namespace App\Models;
use Redis;
//用户登录是否在有效期内
class UserHasLoginRedis{
  public $deadline;
  public $uid;
  public $status;
  public $allowLoginTime=2592000;//一个月
  public function __construct($access_token,$arr=array()){
  	$redis=new Redis();
	$redis->pconnect('localhost', 6379);
	if(!$arr){
		$userLoginStatus=$redis->hmget($access_token, array('uid', 'deadline'));
		if($userLoginStatus){
			$this->uid=$userLoginStatus['uid']; 
			$this->deadline=$userLoginStatus['deadline'];
		  	if(time()<$this->deadline){
		  		$this->status=1;
		  	}else{//过期
		  		$redis->del($access_token);
		  		$this->status=0;
		  	}			
		}else{//不存在这个access_token
	  		$this->status=0;
		}
	}else{
		$this->status=$redis->hmset($access_token, array('uid' =>$arr[0],'deadline'=>$arr[1]+$this->allowLoginTime));  
	}
  }
}
